package edu.langnan.xiaoli.controller.business;

import edu.langnan.xiaoli.base.AjaxResult;
import edu.langnan.xiaoli.base.controller.BaseController;
import edu.langnan.xiaoli.config.security.TokenService;
import edu.langnan.xiaoli.core.domain.CommentDO;
import edu.langnan.xiaoli.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Date;

/**
 * @author cql
 */
@RestController
@RequestMapping("comment")
public class CommentController extends BaseController {

    @Autowired
    private CommentService commentService;

    @Autowired
    private TokenService tokenService;

    /**
     * 发布评论
     *
     * @param commentDO
     * @param request
     * @return
     */
    @PostMapping
    public AjaxResult sendComment(@Valid @RequestBody CommentDO commentDO, HttpServletRequest request) {
        Integer fromId = tokenService.getLoginUser(request).getId();
        commentDO.setFromId(fromId);
        commentDO.setCreateTime(new Date());
        commentService.insertComment(commentDO);
        return AjaxResult.success();
    }


}
